import axios from './axios.ts'


// 获取用户聊天记录
export function getUserChat(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/getUserChat',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 撤销聊天记录
export function cancelChat(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/cancelChat',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 删除聊天记录
export function deleteChat(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/deleteChat',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取近期聊天对象
export function getRecentChat(user_id:number):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: `api/getRecentChat?user_id=${user_id}`,
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 删除近期聊天对象
export function deleteRecentChat(news_id:number):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: `api/deleteRecentChat?news_id=${news_id}`,
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取所有未读消息
export function getUnreadMsg(user_id:number):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: `api/getUnreadMsg?user_id=${user_id}`,
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取用户收到的赞
export function getUserLike(user_id:number):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: `api/getUserLike?user_id=${user_id}`,
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}
